package com.hashTable;

import java.util.HashMap;
import java.util.Objects;

public class FourSumII0131_454 {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        int res = 0;
        HashMap<Integer, Integer> map = new HashMap<>(); // <sum12,count次数>
        for (int i = 0; i < nums1.length; i++) {
            for (int j = 0; j < nums2.length; j++) {
                int sum = nums1[i] + nums2[j];
                map.put(sum,map.getOrDefault(sum,0)+1);
            }
        }

        for (int i = 0; i < nums3.length; i++) {
            for (int j = 0; j < nums4.length; j++) {
                if(map.containsKey(-nums3[i]-nums4[j])) res += map.get(-nums3[i]-nums4[j]);
            }
        }

        return res;
    }
}
